<template>
	<view class="flex-col page">
		<view>
			<view :style="{height:statusBarHeight+'px'}"></view>
			<u-navbar :title="title" bgColor="#F5F5F5" @leftClick="$nav(2)">	
			</u-navbar>
		</view>
		
		<view class="flex-col" v-if="list.length > 0">
			<ProductItem :list="list"></ProductItem>
			
			<u-loadmore margin-top="20" margin-bottom="20" :status="status" icon-type="flower"
				:load-text="loadText" />
		</view>
		
		
		
		
			
		<view v-else class="flex-col items-center" style="margin-top: 80rpx;">
			<image src="/static/data_empty.png"></image>
			<text style="color: #c0c4cc;">暂无数据</text>
		</view>
	</view>
</template>

<script>
	import ProductItem from '@/components/product-item.vue';
	export default {
		data() {
			return {
				title:'',
				tab:0,
				page:1,
				status: 'loadmore',
				loadText: {
					loadmore: '下拉加载更多...',
					loading: '加载中...',
					nomore: '没有更多数据了...'
				},
				list:[]
			};
		},
		components:{
			ProductItem
		},
		computed:{
			statusBarHeight(){
				return this.$store.state.statusBarHeight + 44
			}
		},
		onLoad(op) {
			this.title = op.title
			this.tab = op.index
			this.list = [];
			this.page = 1;
			this.goodsList();
		},
		onShow() {
			
		},
		onPullDownRefresh() {
			this.list = [];
			this.page = 1;
			this.goodsList();
		},
		onReachBottom() {
			this.goodsList();
		},
		methods:{
			goodsList(){
				this.$request({
					url:'?c=Goods&a=goodsList',
					type:'post',
					data:{
						category_id:this.tab,
						page:this.page,
						limit: 10
					}
				}).then(res =>{
					uni.stopPullDownRefresh();
					this.status = 'loadmore';
					if (res.data && res.data.length > 0) {
						this.list = [...this.list, ...res.data];
						this.page += 1;
						if (res.data.length < 10) {
							this.status = 'nomore';
						}
					} else {
						this.status = 'nomore';
					}
					
				});
			}
		}
	}
</script>

<style lang="scss">
.page{
	width: 100%;
	overflow-y: auto;
	overflow-x: hidden;
	height: 100%;
}
</style>
